package com.zhangtai.modules.controller.admin;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dao.EmployeeInfoDao;
import com.zhangtai.modules.dao.OrgGroupDao;
import com.zhangtai.modules.dto.EffectTimeDto;
import com.zhangtai.modules.dto.EmployeeOverworkPageDto;
import com.zhangtai.modules.vo.EffectPersonCountVO;
import com.zhangtai.modules.vo.EffectiveTimeVo;
import com.zhangtai.modules.vo.HrEffectiveReportVO;
import com.zhangtai.utils.PageResult;
import com.zhangtai.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 *
 */
@Api(tags="人事效能报表")
@RestController
@RequestMapping("HrEffectiveReport")
@Slf4j
public class HrEffectiveReportController {

@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private EmployeeInfoDao employeeInfoDao;


    public static void main(String[] args) {

    }


    @GetMapping("/getHrEffectiveReport")
    @ApiOperation(value="查询-人事效能报表")
    public R<HrEffectiveReportVO> getHrEffectiveReport(@RequestParam("beginTime") String beginTime,@RequestParam("endTime") String endTime,
            @RequestParam("beOrgGroupID") String beOrgGroupID,@RequestParam("typeDate") Integer typeDate,@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<EffectiveTimeVo> page = new Page(pageNum,pageSize);
        List<EffectiveTimeVo> effectiveTimeVos = new ArrayList<EffectiveTimeVo>();
        // sys_org_group 根据传进来的公司组id 获取公司id集合
        List<Long> orgIds= orgGroupDao.getOrgIdsByGroupId(new Long(beOrgGroupID));

        List<EffectTimeDto> dayRecruitList = employeeInfoDao.getDayRecruitList(orgIds, beginTime, endTime);

        //组装招聘人员集合
        // [   时间段1 [ 招聘管理 [张三：1， 李四：2]   员工录用 [张三：1， 李四：2]]   时间段2[招聘管理 [张三：1， 李四：2]   员工录用 [张三：1， 李四：2]]      ]
        EffectPersonCountVO countVO = new EffectPersonCountVO();
        countVO.setDimension("招聘人员");
        for (EffectTimeDto etDtoOuter:dayRecruitList
                ) {
            EffectiveTimeVo timeVo = new EffectiveTimeVo();
            if (timeVo.getTimeQue() == null) {
                timeVo.setTimeQue(etDtoOuter.getTimeQue());
            }
            for (EffectTimeDto etDto : dayRecruitList
                    ) {
                if (timeVo.getTimeQue().equals(etDto)) {
                    Map<String, Integer> recuMap = new HashMap<String, Integer>();
                    recuMap.put(etDto.getCreator(), etDto.getNum());
                    countVO.setCreatorCountMap(recuMap);
                }
            }
        }
//        PageResult pageResult = employeeOverworkService.queryPage(oprationName, pageNum, pageSize,request);


        page.setRecords(effectiveTimeVos);
        PageResult pageResult = new PageResult(page);
        return R.ok(pageResult);

    }


}

